package Work01;

import java.util.Objects;

public class Student {
    // 定义一个Student类，属性：姓名、性别、年龄。<br />在性别的set方法中判断是否是男/女，
    //在年龄的set方法中判断年龄是否是15--50之间，如果不是则抛出：年龄异常
    private String name;
    private String sex;
    private int age;

    public Student() {
    }

    public Student(String name, String sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) throws SexException {

        if (sex.equals("男")) {
            this.sex = "男";
        } else if (sex.equals("女")) {
            this.sex = "女";
        } else {
            throw new SexException("性别异常");
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if (age >= 15 && age <= 50) {
            this.age = age;
            System.out.println(this.age);
        }else {
            throw new AgeException("年龄异常");
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(sex, student.sex);
    }


}
